/**
 * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.srwl.mytx.activity.ConversationActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ProgressBar;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.srwl.easeui.widget.MyTitleBar;
import com.srwl.mytx.Constant;
import com.srwl.mytx.R;
import com.srwl.mytx.activity.BaseActivity;
import com.srwl.mytx.adapter.AdvertisementNotifyAdapter;
import com.srwl.mytx.adapter.NotifyMessageInteractionListener;
import com.srwl.mytx.adapter.TransferNotifyAdapter;
import com.srwl.mytx.im.conversation.Conversation;
import com.srwl.mytx.domain.Message;
import com.srwl.mytx.domain.User;
import com.srwl.mytx.im.ConversationService;
import com.srwl.mytx.im.IMSClientBootstrap;
import com.srwl.mytx.widget.ConfirmDialog;

import java.util.ArrayList;
import java.util.List;

import me.dkzwm.widget.srl.MaterialSmoothRefreshLayout;
import me.dkzwm.widget.srl.SmoothRefreshLayout;

/**
 * 广告通知页面
 */
public class AdvertisementNotifyActivity extends SystemNotifyActivity   {
    public static final int REQUEST_CODE_TO_INCREASE_DEPOSIT = 0;
    public static final int REQUEST_CODE_TO_SET_ADVERTISEMENT = 1;

    @NonNull
    @Override
    protected void initConversation() {
        conversation = conversationService.getNotifyConversation(Constant.CONVERSATION_TYPE_ADVERTISEMENT );
        adapter = new AdvertisementNotifyAdapter(this, notifyList, this);
    }

//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//
//        if (resultCode != RESULT_OK) {
//            return;
//        }
//        Advertisement updateAdvertisement = data.getParcelableExtra("advertisement");
//        if (updateAdvertisement == null) {
//            return;
//        }
//        if (requestCode == REQUEST_CODE_TO_SET_ADVERTISEMENT) {
//
//            for (int i = 0; i < notifyList.size(); i++) {
//                Message notify = notifyList.get(i);
//                //必须对消息子分类进行判断，因为消息列表中不同的消息里面附带的都是同一个 advertisement,单纯以advertisement.getId() 来做比较后就更新，会出问题，
//                if (notify.getSubType() == Constant.PUSH_MESSAGE_ADVERTISEMENT_NEED_SET_SHOW_CONTENT) {
//                    Advertisement advertisement = JSONObject.parseObject(notify.getExtraData(), Advertisement.class);
//                    if (advertisement == null) {
//                        continue;
//                    }
//                    if (TextUtils.equals(updateAdvertisement.getId(), advertisement.getId())) {
//                        notify.setExtraData(JSONObject.toJSONString(updateAdvertisement));
//                        adapter.notifyItemChanged(i);
//                        //如果广告位更新后，需要展示到会话列表页面，得在conversation 中写个update(Message msg)的方法，更通过回调，通知会话列表更新，
//                        //而不能在这儿直接更新进数据库
//                        DBManager.getInstance().getDaoSession().getMessageDao().update(notify);
//                        break;
//                    }
//                }
//
//            }
//        } else if (requestCode == REQUEST_CODE_TO_INCREASE_DEPOSIT) {
//
//            for (int i = 0; i < notifyList.size(); i++) {
//                Message notify = notifyList.get(i);
//                if (notify.getSubType() == Constant.PUSH_MESSAGE_ADVERTISEMENT_DEPOSIT_NOT_ENOUGH) {
//                    Advertisement advertisement = JSONObject.parseObject(notify.getExtraData(), Advertisement.class);
//                    if (advertisement == null) {
//                        continue;
//                    }
//                    if (TextUtils.equals(updateAdvertisement.getId(), advertisement.getId())) {
//                        notify.setExtraData(JSONObject.toJSONString(updateAdvertisement));
//                        adapter.notifyItemChanged(i);
//                        //如果广告位更新后，需要展示到会话列表页面，得在conversation 中写个update(Message msg)的方法，更通过回调，通知会话列表更新，
//                        //而不能在这儿直接更新进数据库
//                        DBManager.getInstance().getDaoSession().getMessageDao().update(notify);
//                        break;
//                    }
//                }
//            }
//        }
//    }
}
